from flask import Blueprint
from flask_restx import Api

from app.role_control import (
    MenuControl,
    PermissionBlueprintControl,
    PermissionTreeControl,
    RolePermissionControl,
    RoleSetControl,
)

permissionBlueprint = Blueprint(
    "permission_control",
    __name__,
    url_prefix="/v1/permission",
    role_control=PermissionBlueprintControl,
)
per_control = Api(permissionBlueprint)

from . import views  # isort:skip

# 获取角色权限树
per_control.add_resource(
    views.PermissionTreeView,
    "/tree",
    endpoint="/v1/permission/tree",
    role_control=PermissionTreeControl,
)
# 获取角色信息列表
per_control.add_resource(views.RoleSetView, "/roles", role_control=RoleSetControl)
# 获取用户动态菜单
per_control.add_resource(views.MenuView, "/menu", role_control=MenuControl)
# 获取某角色权限/绑定用户与角色
per_control.add_resource(
    views.RolePermissionView,
    "/role/<int:role_id>",
    "/role/<int:role_id>/<int:user_id>",
    role_control=RolePermissionControl,
)
